﻿define(
	[
		"Libraries/KOWidgets/Shared/BaseKOWidget",
		"Libraries/ThirdParty/Require/text!Libraries/KOWidgets/FastOrderControl/FastOrderControl.html"
	],
	function (baseKOWidget, fastOrderControlView) {
	    $.step.BaseKOWidget.injectCssFile("Libraries_KOWidgets_FastOrderControl_FastOrderControl", require.toUrl("Libraries/KOWidgets/FastOrderControl/FastOrderControl.css"));


	    (function ($, undefined) {
	        $.widget("step.FastOrderControl", $.step.BaseKOWidget,
			{
			    // Default options.
			    options: {
			        view: fastOrderControlView,
			    },
			    GetSubmitFields: function () {
			        var fields = this.FlattenModelToData();

			        return fields;
			    },

			    _createDefaultModel: function () {
			        var widgetThis = this;
			        
			        var myViewModel = function () {
			            var self = this;
			            this.Text = ko.observable("");

			            this.Team = ko.observable([]);

			            this.btnClick = function () {
			                var txt = prompt("Enter new text", self.Text());
			                widgetThis.SetText(txt);
			            };

			        };

			        return new myViewModel();

			    },
			    _Close: function () {
			        this._ClearModel();
			    },
			    _ClearModel: function () {
			        var model = this.options.model;
			        model.Text("");
			    },

			    _create: function () {
			        var self = this;
			        this._initModel();
			        this._initView();
			        this._initKO();
			        var model = this.options.model;

			        if (!this.element.hasClass("step-FastOrderControl")) {
			            this.element.addClass("step-FastOrderControl");
			        }

			        var arr = [];
			        for (var i = 0; i < 5; i++) {
			            var obj = { name: "name" + i, number: i };
			            arr.push(obj);
			        }

			        model.Team(arr);
			        //model.OKbutton.subscribe(function (newValue) {
			        //    $(".buttons", self.element).children("a").first().children("span").text(newValue);
			        //});
			    },
			    SetText : function(text)
			    {
			        var txt = text || "Default text";

			        this.options.model.Text(txt);
			    },
			    Show: function () {
			        //this.element.dialog({
			        //    modal: true,
			        //    resizable: false,
			        //    width: 360,
			        //    height: (this.options.model.IsCommentsVisible()) ? 230 : 130,
			        //    title: this.options.model.Title()
			        //});
			        //this.element.dialog("show");
			    },
			    _setOption: function (key, value) {
			        this._handleModelViewSetOption(key, value);
			        $.Widget.prototype._setOption.apply(this, arguments);
			    }

			});
	    })(jQuery);
	    return "success - step-FastOrderControl";
	}
);